﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Rendering.StencilState
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;

#nullable disable
namespace UnityEngine.Rendering
{
  /// <summary>
  ///   <para>Values for the stencil state.</para>
  /// </summary>
  /// <summary>
  ///   <para>Creates a new stencil state with the given values.</para>
  /// </summary>
  /// <param name="readMask">An 8 bit mask as an 0–255 integer, used when comparing the reference value with the contents of the buffer.</param>
  /// <param name="writeMask">An 8 bit mask as an 0–255 integer, used when writing to the buffer.</param>
  /// <param name="enabled">Controls whether the stencil buffer is enabled.</param>
  /// <param name="compareFunctionFront">The function used to compare the reference value to the current contents of the buffer for front-facing geometry.</param>
  /// <param name="passOperationFront">What to do with the contents of the buffer if the stencil test (and the depth test) passes for front-facing geometry.</param>
  /// <param name="failOperationFront">What to do with the contents of the buffer if the stencil test fails for front-facing geometry.</param>
  /// <param name="zFailOperationFront">What to do with the contents of the buffer if the stencil test passes, but the depth test fails for front-facing geometry.</param>
  /// <param name="compareFunctionBack">The function used to compare the reference value to the current contents of the buffer for back-facing geometry.</param>
  /// <param name="passOperationBack">What to do with the contents of the buffer if the stencil test (and the depth test) passes for back-facing geometry.</param>
  /// <param name="failOperationBack">What to do with the contents of the buffer if the stencil test fails for back-facing geometry.</param>
  /// <param name="zFailOperationBack">What to do with the contents of the buffer if the stencil test passes, but the depth test fails for back-facing geometry.</param>
  /// <param name="compareFunction">The function used to compare the reference value to the current contents of the buffer.</param>
  /// <param name="passOperation">What to do with the contents of the buffer if the stencil test (and the depth test) passes.</param>
  /// <param name="failOperation">What to do with the contents of the buffer if the stencil test fails.</param>
  /// <param name="zFailOperation">What to do with the contents of the buffer if the stencil test passes, but the depth test.</param>
  public struct StencilState(
    bool enabled,
    byte readMask,
    byte writeMask,
    CompareFunction compareFunctionFront,
    StencilOp passOperationFront,
    StencilOp failOperationFront,
    StencilOp zFailOperationFront,
    CompareFunction compareFunctionBack,
    StencilOp passOperationBack,
    StencilOp failOperationBack,
    StencilOp zFailOperationBack) : IEquatable<StencilState>
  {
    private byte m_Enabled = Convert.ToByte(enabled);
    private byte m_ReadMask = readMask;
    private byte m_WriteMask = writeMask;
    private byte m_Padding = 0;
    private byte m_CompareFunctionFront = (byte) compareFunctionFront;
    private byte m_PassOperationFront = (byte) passOperationFront;
    private byte m_FailOperationFront = (byte) failOperationFront;
    private byte m_ZFailOperationFront = (byte) zFailOperationFront;
    private byte m_CompareFunctionBack = (byte) compareFunctionBack;
    private byte m_PassOperationBack = (byte) passOperationBack;
    private byte m_FailOperationBack = (byte) failOperationBack;
    private byte m_ZFailOperationBack = (byte) zFailOperationBack;

    /// <summary>
    ///   <para>Default values for the stencil state.</para>
    /// </summary>
    public static StencilState defaultValue => new StencilState();

    /// <summary>
    ///   <para>Creates a new stencil state with the given values.</para>
    /// </summary>
    /// <param name="readMask">An 8 bit mask as an 0–255 integer, used when comparing the reference value with the contents of the buffer.</param>
    /// <param name="writeMask">An 8 bit mask as an 0–255 integer, used when writing to the buffer.</param>
    /// <param name="enabled">Controls whether the stencil buffer is enabled.</param>
    /// <param name="compareFunctionFront">The function used to compare the reference value to the current contents of the buffer for front-facing geometry.</param>
    /// <param name="passOperationFront">What to do with the contents of the buffer if the stencil test (and the depth test) passes for front-facing geometry.</param>
    /// <param name="failOperationFront">What to do with the contents of the buffer if the stencil test fails for front-facing geometry.</param>
    /// <param name="zFailOperationFront">What to do with the contents of the buffer if the stencil test passes, but the depth test fails for front-facing geometry.</param>
    /// <param name="compareFunctionBack">The function used to compare the reference value to the current contents of the buffer for back-facing geometry.</param>
    /// <param name="passOperationBack">What to do with the contents of the buffer if the stencil test (and the depth test) passes for back-facing geometry.</param>
    /// <param name="failOperationBack">What to do with the contents of the buffer if the stencil test fails for back-facing geometry.</param>
    /// <param name="zFailOperationBack">What to do with the contents of the buffer if the stencil test passes, but the depth test fails for back-facing geometry.</param>
    /// <param name="compareFunction">The function used to compare the reference value to the current contents of the buffer.</param>
    /// <param name="passOperation">What to do with the contents of the buffer if the stencil test (and the depth test) passes.</param>
    /// <param name="failOperation">What to do with the contents of the buffer if the stencil test fails.</param>
    /// <param name="zFailOperation">What to do with the contents of the buffer if the stencil test passes, but the depth test.</param>
    public StencilState(
      bool enabled = true,
      byte readMask = 255,
      byte writeMask = 255,
      CompareFunction compareFunction = CompareFunction.Always,
      StencilOp passOperation = StencilOp.Keep,
      StencilOp failOperation = StencilOp.Keep,
      StencilOp zFailOperation = StencilOp.Keep)
      : this(enabled, readMask, writeMask, compareFunction, passOperation, failOperation, zFailOperation, compareFunction, passOperation, failOperation, zFailOperation)
    {
    }

    /// <summary>
    ///   <para>Controls whether the stencil buffer is enabled.</para>
    /// </summary>
    public bool enabled
    {
      get => Convert.ToBoolean(this.m_Enabled);
      set => this.m_Enabled = Convert.ToByte(value);
    }

    /// <summary>
    ///   <para>An 8 bit mask as an 0–255 integer, used when comparing the reference value with the contents of the buffer.</para>
    /// </summary>
    public byte readMask
    {
      get => this.m_ReadMask;
      set => this.m_ReadMask = value;
    }

    /// <summary>
    ///   <para>An 8 bit mask as an 0–255 integer, used when writing to the buffer.</para>
    /// </summary>
    public byte writeMask
    {
      get => this.m_WriteMask;
      set => this.m_WriteMask = value;
    }

    /// <summary>
    ///   <para>The function used to compare the reference value to the current contents of the buffer.</para>
    /// </summary>
    /// <param name="value">The value to set.</param>
    public void SetCompareFunction(CompareFunction value)
    {
      this.compareFunctionFront = value;
      this.compareFunctionBack = value;
    }

    /// <summary>
    ///   <para>What to do with the contents of the buffer if the stencil test (and the depth test) passes.</para>
    /// </summary>
    /// <param name="value">The value to set.</param>
    public void SetPassOperation(StencilOp value)
    {
      this.passOperationFront = value;
      this.passOperationBack = value;
    }

    /// <summary>
    ///   <para>What to do with the contents of the buffer if the stencil test fails.</para>
    /// </summary>
    /// <param name="value">The value to set.</param>
    public void SetFailOperation(StencilOp value)
    {
      this.failOperationFront = value;
      this.failOperationBack = value;
    }

    /// <summary>
    ///   <para>What to do with the contents of the buffer if the stencil test passes, but the depth test fails.</para>
    /// </summary>
    /// <param name="value">The value to set.</param>
    public void SetZFailOperation(StencilOp value)
    {
      this.zFailOperationFront = value;
      this.zFailOperationBack = value;
    }

    /// <summary>
    ///   <para>The function used to compare the reference value to the current contents of the buffer for front-facing geometry.</para>
    /// </summary>
    public CompareFunction compareFunctionFront
    {
      get => (CompareFunction) this.m_CompareFunctionFront;
      set => this.m_CompareFunctionFront = (byte) value;
    }

    /// <summary>
    ///   <para>What to do with the contents of the buffer if the stencil test (and the depth test) passes for front-facing geometry.</para>
    /// </summary>
    public StencilOp passOperationFront
    {
      get => (StencilOp) this.m_PassOperationFront;
      set => this.m_PassOperationFront = (byte) value;
    }

    /// <summary>
    ///   <para>What to do with the contents of the buffer if the stencil test fails for front-facing geometry.</para>
    /// </summary>
    public StencilOp failOperationFront
    {
      get => (StencilOp) this.m_FailOperationFront;
      set => this.m_FailOperationFront = (byte) value;
    }

    /// <summary>
    ///   <para>What to do with the contents of the buffer if the stencil test passes, but the depth test fails for front-facing geometry.</para>
    /// </summary>
    public StencilOp zFailOperationFront
    {
      get => (StencilOp) this.m_ZFailOperationFront;
      set => this.m_ZFailOperationFront = (byte) value;
    }

    /// <summary>
    ///   <para>The function used to compare the reference value to the current contents of the buffer for back-facing geometry.</para>
    /// </summary>
    public CompareFunction compareFunctionBack
    {
      get => (CompareFunction) this.m_CompareFunctionBack;
      set => this.m_CompareFunctionBack = (byte) value;
    }

    /// <summary>
    ///   <para>What to do with the contents of the buffer if the stencil test (and the depth test) passes for back-facing geometry.</para>
    /// </summary>
    public StencilOp passOperationBack
    {
      get => (StencilOp) this.m_PassOperationBack;
      set => this.m_PassOperationBack = (byte) value;
    }

    /// <summary>
    ///   <para>What to do with the contents of the buffer if the stencil test fails for back-facing geometry.</para>
    /// </summary>
    public StencilOp failOperationBack
    {
      get => (StencilOp) this.m_FailOperationBack;
      set => this.m_FailOperationBack = (byte) value;
    }

    /// <summary>
    ///   <para>What to do with the contents of the buffer if the stencil test passes, but the depth test fails for back-facing geometry.</para>
    /// </summary>
    public StencilOp zFailOperationBack
    {
      get => (StencilOp) this.m_ZFailOperationBack;
      set => this.m_ZFailOperationBack = (byte) value;
    }

    public bool Equals(StencilState other)
    {
      return (int) this.m_Enabled == (int) other.m_Enabled && (int) this.m_ReadMask == (int) other.m_ReadMask && (int) this.m_WriteMask == (int) other.m_WriteMask && (int) this.m_CompareFunctionFront == (int) other.m_CompareFunctionFront && (int) this.m_PassOperationFront == (int) other.m_PassOperationFront && (int) this.m_FailOperationFront == (int) other.m_FailOperationFront && (int) this.m_ZFailOperationFront == (int) other.m_ZFailOperationFront && (int) this.m_CompareFunctionBack == (int) other.m_CompareFunctionBack && (int) this.m_PassOperationBack == (int) other.m_PassOperationBack && (int) this.m_FailOperationBack == (int) other.m_FailOperationBack && (int) this.m_ZFailOperationBack == (int) other.m_ZFailOperationBack;
    }

    public override bool Equals(object obj)
    {
      return obj != null && obj is StencilState other && this.Equals(other);
    }

    public override int GetHashCode()
    {
      return (((((((((this.m_Enabled.GetHashCode() * 397 ^ this.m_ReadMask.GetHashCode()) * 397 ^ this.m_WriteMask.GetHashCode()) * 397 ^ this.m_CompareFunctionFront.GetHashCode()) * 397 ^ this.m_PassOperationFront.GetHashCode()) * 397 ^ this.m_FailOperationFront.GetHashCode()) * 397 ^ this.m_ZFailOperationFront.GetHashCode()) * 397 ^ this.m_CompareFunctionBack.GetHashCode()) * 397 ^ this.m_PassOperationBack.GetHashCode()) * 397 ^ this.m_FailOperationBack.GetHashCode()) * 397 ^ this.m_ZFailOperationBack.GetHashCode();
    }

    public static bool operator ==(StencilState left, StencilState right) => left.Equals(right);

    public static bool operator !=(StencilState left, StencilState right) => !left.Equals(right);
  }
}
